package com.linkoog.devtools.code_generator.action.code;

import com.linkoog.devtools.code_generator.wizard.generate.ctrl_service.GenCtrlAndServiceDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

public class ControllerAndServiceAction extends AnAction implements DumbAware {


    @Override
    public void actionPerformed(@NotNull AnActionEvent event) {
        Project project = event.getProject();
        if (project == null){
            return;
        }

        Module module = event.getData(LangDataKeys.MODULE);
        if (module == null){
            return;
        }


        VirtualFile selectedPackageVF = event.getData(LangDataKeys.VIRTUAL_FILE);
        if (selectedPackageVF == null || !selectedPackageVF.isDirectory()){
            return;
        }

        GenCtrlAndServiceDialog dialog = new GenCtrlAndServiceDialog(project, module, selectedPackageVF);
        if (!dialog.showAndGet()) {
            return;
        }
    }

}
